function Food(ele) {
    this.ele = ele
    this.len = 20
    this.foodobj = null
    this.foodX = 0
    this.foodY = 0
}
Food.prototype.create = function () {
    let divobj = document.createElement('div')
    divobj.style.width = this.len + 'px'
    divobj.style.height = this.len + 'px'
    divobj.style.background = 'green'
    divobj.style.position = 'absolute'
    // 单独保存食物
    this.foodobj = divobj
    // 在页面上显示 
    this.ele.appendChild(divobj)
    this.move()
}

// 食物随机显示
Food.prototype.move = function () {
    let foodXMax = this.ele.clientWidth / this.len - 1
    let foodYMax = this.ele.clientHeight / this.len - 1
    // 随机个数*每个食物的宽度
    this.foodX = Math.floor(Math.random() * (foodXMax + 1)) * this.len
    this.foodY = Math.floor(Math.random() * (foodYMax + 1)) * this.len
    this.foodobj.style.left = this.foodX
    this.foodobj.style.top = this.foodY
}